//
//  FZHomeStatusOriginalView.swift
//  FZSina_Swift
//
//  Created by 李忠 on 7/24/16.
//  Copyright © 2016 FZLZ. All rights reserved.
//

import UIKit

class FZHomeStatusOriginalView: UIView {
    
    var status: FZHomeStatusViewModel?{
        
        didSet{
            
            let header = status?.status?.user?.profile_image_url ?? ""
            headerIMGView.fz_setImage(header)
            nameLabel.text = status?.name!
            
            timeLabel.text = formatedTime((status?.status?.created_at)!)
            sourceLabel.text = status?.source!
            contentLabel.text = status?.content
            memberIMGView.image = status?.vipIMG
            avatarIMGView.image = status?.avatarIMG
            
            pictueView.pictureInfo = status?.status?.pic_urls
            
        }
        
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        setupLayout()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK:==========================加载界面==========================
    private func setupUI(){
        self.backgroundColor = UIColor.whiteColor()
        addSubview(headerIMGView)
        addSubview(nameLabel)
        addSubview(memberIMGView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(avatarIMGView)
        addSubview(contentLabel)
        addSubview(pictueView)
        
    }
    private func setupLayout() {
        headerIMGView.snp_makeConstraints { (make) in
            make.top.leading.equalTo(PADDING)
            make.size.equalTo(CGSizeMake(PADDING * 3.0, PADDING * 3.0))
        }
        nameLabel.snp_makeConstraints { (make) in
            make.top.equalTo(headerIMGView)
            make.leading.equalTo(headerIMGView.snp_trailing).offset(PADDING)
        }
        memberIMGView.snp_makeConstraints { (make) in
            make.centerY.equalTo(nameLabel)
            make.leading.equalTo(nameLabel.snp_trailing).offset(PADDING)
        }
        avatarIMGView.snp_makeConstraints { (make) in
            make.centerX.equalTo(headerIMGView.snp_trailing)
            make.centerY.equalTo(headerIMGView.snp_bottom)
        }
        timeLabel.snp_makeConstraints { (make) in
            make.bottom.equalTo(headerIMGView.snp_bottom)
            make.leading.equalTo(headerIMGView.snp_trailing).offset(PADDING)
        }
        sourceLabel.snp_makeConstraints { (make) in
            make.leading.equalTo(timeLabel.snp_trailing).offset(PADDING)
            make.bottom.equalTo(headerIMGView.snp_bottom)
        }
        contentLabel.snp_makeConstraints { (make) in
            make.top.equalTo(headerIMGView.snp_bottom).offset(PADDING)
            make.leading.equalTo(headerIMGView.snp_leading)
        }
        
        pictueView.snp_makeConstraints { (make) in
            
            make.top.equalTo(contentLabel.snp_bottom).offset(PADDING)
            make.leading.equalTo(headerIMGView.snp_leading)
            make.bottom.equalTo(self).offset(0)
            
        }
    }

//MARK:==========================懒加载==========================
    ///头像
    private lazy var headerIMGView: UIImageView = UIImageView()
    ///名字
    private lazy var nameLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 12)
    ///vip图标
    private lazy var memberIMGView: UIImageView = UIImageView()
    ///发表时间
    private lazy var timeLabel: UILabel = UILabel(textColor: UIColor.orangeColor(), textFont: 10)
    ///来源
    private lazy var sourceLabel: UILabel = UILabel(textColor: UIColor.grayColor(), textFont: 10)
    ///认证logo
    private lazy var avatarIMGView: UIImageView = UIImageView()
    ///微博内容
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 12, width: SCREENW - 2 * PADDING)
    //图片
    private lazy var pictueView: FZHomeStatusPictureView = {
        let flowlayout = UICollectionViewFlowLayout()
        let vi: FZHomeStatusPictureView = FZHomeStatusPictureView(frame: CGRectZero, collectionViewLayout: flowlayout)
        return vi
    }()
    
}
